<template>
  <el-dialog v-model="visibleProxy" title="计划进度" width="520px" destroy-on-close>
    <div class="timeline-stats">
      <div class="progress-group">
        <div class="progress-item">
          <div class="progress-header">
            <span class="progress-label">计划总天数</span>
            <span class="progress-text">{{ planStats.executedDays }}/{{ planStats.totalDays }}天</span>
          </div>
          <el-progress :percentage="daysProgress" :stroke-width="8" :show-text="false" color="#52c41a" />
        </div>
      </div>
      <div class="progress-group">
        <div class="progress-item">
          <div class="progress-header">
            <span class="progress-label">计划总任务数</span>
            <span class="progress-text">{{ planStats.executedTasks }}/{{ planStats.totalTasks }}个</span>
          </div>
          <el-progress :percentage="tasksProgress" :stroke-width="8" :show-text="false" color="#52c41a" />
        </div>
      </div>
    </div>
    <div class="timeline-wrapper">
      <el-timeline>
        <el-timeline-item v-for="(item, idx) in timelineData" :key="idx" :timestamp="'执行时间：' + item.time" :type="item.type" :color="item.color">
          <div class="timeline-card">
            <div class="timeline-title">{{ item.content }}</div>
            <div class="timeline-meta">
              <!-- <span v-if="item.user">操作人：{{ item.user }}</span> -->
              <span v-if="item.remark" class="timeline-remark" :class="item.statusClass">{{ item.remark }}</span>
            </div>
          </div>
        </el-timeline-item>
      </el-timeline>
    </div>
  </el-dialog>
</template>

<script lang="ts" setup>
import { computed } from 'vue';
import { Check } from '@element-plus/icons-vue';

const props = defineProps<{
  visible: boolean;
  planStats: {
    totalDays: number;
    executedDays: number;
    totalTasks: number;
    executedTasks: number;
  };
  timelineData: Array<{
    time: string;
    content: string;
    type: string;
    icon?: string;
    color?: string;
    user?: string;
    remark?: string;
    statusClass?: string;
  }>;
}>();
const emit = defineEmits(['update:visible']);
const visibleProxy = computed({
  get: () => props.visible,
  set: (val: boolean) => emit('update:visible', val)
});

// 计算进度百分比
const daysProgress = computed(() => {
  if (!props.planStats.totalDays || props.planStats.totalDays === 0) return 0;
  return Math.round((props.planStats.executedDays / props.planStats.totalDays) * 100);
});

const tasksProgress = computed(() => {
  if (!props.planStats.totalTasks || props.planStats.totalTasks === 0) return 0;
  return Math.round((props.planStats.executedTasks / props.planStats.totalTasks) * 100);
});
</script>

<style lang="scss" scoped>
.timeline-stats {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-bottom: 20px;
  padding: 16px;
  background: #fafbfc;
  border-radius: 8px;

  .progress-group {
    width: 100%;
  }

  .progress-item {
    .progress-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 8px;

      .progress-label {
        font-size: 14px;
        font-weight: 600;
        color: #333;
      }

      .progress-text {
        font-size: 13px;
        color: #52c41a;
        font-weight: 600;
      }
    }
  }
}

.timeline-wrapper {
  padding: 8px 0 0 0;
}
.timeline-card {
  background: #fafbfc;
  border-radius: 6px;
  padding: 10px 14px 8px 14px;
  box-shadow: none;
  margin-bottom: 4px;
  transition: none;
}
.timeline-title {
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 2px;
  color: #222;
}
.timeline-meta {
  color: #888;
  font-size: 12px;
  margin-top: 1px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}
.timeline-remark {
  font-weight: 600;
}
.remark-info {
  color: #409eff;
}
.remark-success {
  color: #67c23a;
}
.remark-danger {
  color: #f56c6c;
}
.remark-warning {
  color: #e6a23c;
}
.remark-unknown {
  color: #909399;
}
:deep(.el-timeline-item__node) {
  box-shadow: none;
  background: #e6f7e6 !important;
  border: none !important;
}
:deep(.el-timeline-item__tail) {
  border-left: 2px solid #f0f0f0 !important;
}

.stat-unit {
  font-size: 13px;
  color: #888;
  font-weight: 400;
  margin-left: 2px;
}
</style>
